package test;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import commons.conf.xml.XmlResourceApplication;
import commons.meta.impl.DefaultRuntimeApplication;

public class MySqlHibernate {

	public static void main(String[] args) throws Exception {

		// mysql.hibernate.cfg.xml

		buildSessionFactory();

	}

	private static Configuration configuration;

	private static SessionFactory buildSessionFactory() {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			
			XmlResourceApplication x = new XmlResourceApplication();
			x.getLocations().add("classpath:commons/conf/example.xml");
			x.afterPropertiesSet();
			DefaultRuntimeApplication app = new DefaultRuntimeApplication();
			app.setResourceApplication(x);
			
			
			
			Configuration conf = new Configuration().configure("/mysql.hibernate.cfg.xml");
			// conf.addFile(xmlFile);
			SessionFactory sf = conf.buildSessionFactory();
			configuration = conf;
			return sf;
		} catch (Throwable ex) {
			// Make sure you log the exception, as it might be swallowed
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

}
